package com.bf.hotpoint.service.impl;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bf.hotpoint.domain.Info;
import com.bf.hotpoint.enums.RedisKeyEnum;
import com.bf.hotpoint.repository.mongo.InfoMongoRepository;
import com.bf.hotpoint.repository.redis.CommonRedisRepository;
import com.bf.hotpoint.service.InfoService;

@Service
public class InfoServiceImpl implements InfoService{

	static Logger log = Logger.getLogger(InfoServiceImpl.class.getName());
	
	@Autowired
	private InfoMongoRepository infoMongoRepository;
	
	@Autowired
	private CommonRedisRepository commonRedisRepository;

	public void addInfo() {
		
		Info info = new Info();
		info.setOperationuuids(commonRedisRepository.getSetByKey(RedisKeyEnum.OPERATION_UUIDS.getKey()));
		info.setPostMessageOf1Mins(commonRedisRepository.getSetByKey(RedisKeyEnum.POST_MESSAGE_OF_1MINS.getKey()));
		info.setPostMessageOf10Mins(commonRedisRepository.getSetByKey(RedisKeyEnum.POST_MESSAGE_OF_10MINS.getKey()));
		info.setPostMessageOf60Mins(commonRedisRepository.getSetByKey(RedisKeyEnum.POST_MESSAGE_OF_60MINS.getKey()));
		info.setNumberOfPostReply(commonRedisRepository.getLongByKey(RedisKeyEnum.NUMBER_OF_POST_REPLY.getKey()));
		info.setNumberOfReport(commonRedisRepository.getLongByKey(RedisKeyEnum.NUMBER_OF_REPORT.getKey()));
		info.setNumberOfPraise(commonRedisRepository.getLongByKey(RedisKeyEnum.NUMBER_OF_PRAISE.getKey()));
		info.setNumberOfDespise(commonRedisRepository.getLongByKey(RedisKeyEnum.NUMBER_OF_DESPISE.getKey()));
		info.setCreateTime(new Date());
		
		infoMongoRepository.addInfo(info);
		
		commonRedisRepository.deleteByKey(RedisKeyEnum.OPERATION_UUIDS.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.POST_MESSAGE_OF_1MINS.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.POST_MESSAGE_OF_10MINS.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.POST_MESSAGE_OF_60MINS.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.NUMBER_OF_POST_REPLY.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.NUMBER_OF_REPORT.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.NUMBER_OF_PRAISE.getKey());
		commonRedisRepository.deleteByKey(RedisKeyEnum.NUMBER_OF_DESPISE.getKey());
	}

	
}
